<template>
  <div class="app-container">

    <el-button type="info" @click="approve">审批</el-button>
    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商户ID" align="center" prop="id" ></el-table-column>
      <el-table-column label="商户名称" align="center" prop="name" ></el-table-column>
      <el-table-column label="法人" align="center" prop="corporation" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="类型" align="center" prop="type" >
        <template slot-scope="scope">
          <div v-if="scope.row.type==1">公司化公寓</div>
          <div v-if="scope.row.type==0">个人职业房东</div>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <div v-if="scope.row.status==1">审核通过</div>
          <div v-if="scope.row.status==2">审核未通过</div>
          <div v-if="scope.row.status==3">待审核</div>
        </template>
      </el-table-column>

      <el-table-column label="管理员" align="center" prop="userName" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">

      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商户名称" prop="name">
          <el-input readonly v-model="form.name" />
        </el-form-item>
        <el-form-item label="法人" prop="corporation">
          <el-input readonly v-model="form.corporation" />
        </el-form-item>
        <el-form-item label="省" prop="provinceName">
          <el-input readonly v-model="form.provinceName" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="市" prop="cityName">
          <el-input readonly v-model="form.cityName" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="区" prop="countryName">
          <el-input readonly v-model="form.countryName" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input readonly v-model="form.address" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-input readonly v-model="form.status==1?'审核通过':form.status==2?'审核未通过':'待审核'"  controls-position="right" :min="0" >待审核</el-input>
        </el-form-item>
        <el-form-item label="管理员" prop="userName">
          <el-input readonly v-model="form.userName" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="统一信征码" prop="zheng">
          <el-input readonly v-model="form.zheng" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="营业执照" prop="roleSort">
          <img :src="form.url" width="100px" height="100px">
        </el-form-item>
        <el-form-item label="申请时间" prop="createTime">
          <el-input readonly v-model="form.createTime" controls-position="right" :min="0" />
        </el-form-item>
        <el-button type="primary" @click="pass">通过</el-button>
        <el-button type="primary" @click="noPass">不通过</el-button>
        <el-button type="primary" @click="this.dialogVisible=false">返回</el-button>
      </el-form>

    </el-dialog>


  </div>
</template>

<script>
import { listBusiness, getInfo, delInfo, addInfo, updateInfo, getBusiness, pass, noPass } from "@/api/system/business";

export default {
  name: "Info",
  components: {
  },
  data() {
    return {
      dialogVisible:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 楼盘信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    pass() {
      pass(this.form.id).then(res=>{
        if(res.code==200){
          this.$message.success("操作成功");
          this.dialogVisible=false;
        }
      })
    },
    noPass() {
      noPass(this.form.id).then(res=>{
        if(res.code==200){
          this.$message.success("操作成功");
          this.dialogVisible=false;
        }
      })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    approve() {
      if(this.ids.length==0){
        this.$message.warning("请选择一条记录");
      }
      if(this.ids.length>1){
        this.$message.warning("只能选择一条记录")
      }
      this.dialogVisible=true;
      this.getBusinessById();
    },
    getBusinessById() {
      getBusiness(this.ids).then(res=>{
        this.form=res.data;
      })
    },
    /** 查询楼盘信息列表 */
    getList() {
      this.loading = true;
      listBusiness(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleSelectionChange(val) {
      this.ids=val.map(row=>row.id)
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {

      };
      this.resetForm("form");
    },
    // /** 搜索按钮操作 */
    // handleQuery() {
    //   this.queryParams.pageNum = 1;
    //   this.getList();
    // },
    // /** 重置按钮操作 */
    // resetQuery() {
    //   this.resetForm("queryForm");
    //   this.handleQuery();
    // },
    // // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.id)
    //   this.single = selection.length!==1
    //   this.multiple = !selection.length
    // },




  }
};
</script>
